home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / oct-strstrm.h < prev    next >
C/C++ Source or Header  |  1997-01-29  |  4KB  |  165 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_octave_strstream_h)
  24. #define octave_octave_strstream_h 1
  25.  
  26. #include <string>
  27.  
  28. #include <strstream.h>
  29.  
  30. #include "oct-stream.h"
  31.  
  32. class
  33. octave_base_strstream : public octave_base_stream
  34. {
  35. public:
  36.  
  37.   octave_base_strstream (ios::openmode arg_md = ios::out,
  38.              oct_mach_info::float_format flt_fmt =
  39.              oct_mach_info::native)
  40.     : octave_base_stream (arg_md, flt_fmt) { }
  41.  
  42.   ~octave_base_strstream (void) { }
  43.  
  44.   // Position a stream at OFFSET relative to ORIGIN.
  45.  
  46.   int seek (streamoff offset, ios::seek_dir origin);
  47.  
  48.   // Return current stream position.
  49.  
  50.   long tell (void) const;
  51.  
  52.   // The name of the file.
  53.  
  54.   string name (void) { return string (); }
  55.  
  56.   virtual streambuf *rdbuf (void) = 0;
  57.  
  58.   virtual bool bad (void) const = 0;
  59.  
  60.   virtual void clear (void) = 0;
  61.  
  62. private:
  63.  
  64.   // No copying!
  65.  
  66.   octave_base_strstream (const octave_base_strstream&);
  67.  
  68.   octave_base_strstream& operator = (const octave_base_strstream&);
  69. };
  70.  
  71. class
  72. octave_istrstream : public octave_base_strstream
  73. {
  74. public:
  75.  
  76.   octave_istrstream (const char *data,
  77.              ios::openmode arg_md = ios::out,
  78.              oct_mach_info::float_format flt_fmt =
  79.              oct_mach_info::native)
  80.     : octave_base_strstream (arg_md, flt_fmt), is (data) { }
  81.  
  82.   octave_istrstream (const string& data,
  83.              ios::openmode arg_md = ios::out,
  84.              oct_mach_info::float_format flt_fmt =
  85.              oct_mach_info::native)
  86.     : octave_base_strstream (arg_md, flt_fmt), is (data.c_str ()) { }
  87.  
  88.   ~octave_istrstream (void) { }
  89.  
  90.   // Return non-zero if EOF has been reached on this stream.
  91.  
  92.   bool eof (void) const { return is.eof (); }
  93.  
  94.   istream *input_stream (void) { return &is; }
  95.  
  96.   ostream *output_stream (void) { return 0; }
  97.  
  98.   streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; }
  99.  
  100.   bool bad (void) const { return is.bad (); }
  101.  
  102.   void clear (void) { is.clear (); }
  103.  
  104. private:
  105.  
  106.   istrstream is;
  107.  
  108.   // No copying!
  109.  
  110.   octave_istrstream (const octave_istrstream&);
  111.  
  112.   octave_istrstream& operator = (const octave_istrstream&);
  113. };
  114.  
  115. class
  116. octave_ostrstream : public octave_base_strstream
  117. {
  118. public:
  119.  
  120.   octave_ostrstream (ios::openmode arg_md = ios::out,
  121.              oct_mach_info::float_format flt_fmt =
  122.              oct_mach_info::native)
  123.     : octave_base_strstream (arg_md, flt_fmt) { }
  124.  
  125.   ~octave_ostrstream (void) { }
  126.  
  127.   // Return non-zero if EOF has been reached on this stream.
  128.  
  129.   bool eof (void) const { return os.eof (); }
  130.  
  131.   istream *input_stream (void) { return 0; }
  132.  
  133.   ostream *output_stream (void) { return &os; }
  134.  
  135.   char *str (void)
  136.     {
  137.       os << ends;
  138.       return os.str ();
  139.     }
  140.  
  141.   streambuf *rdbuf (void) { return os ? os.rdbuf () : 0; }
  142.  
  143.   bool bad (void) const { return os.bad (); }
  144.  
  145.   void clear (void) { os.clear (); }
  146.  
  147. private:
  148.  
  149.   ostrstream os;
  150.  
  151.   // No copying!
  152.  
  153.   octave_ostrstream (const octave_ostrstream&);
  154.  
  155.   octave_ostrstream& operator = (const octave_ostrstream&);
  156. };
  157.  
  158. #endif
  159.  
  160. /*
  161. ;;; Local Variables: ***
  162. ;;; mode: C++ ***
  163. ;;; End: ***
  164. */
  165.